package org.hzz.application.command.user;

import io.gitee.pkmer.convention.page.PageResponse;
import io.gitee.pkmer.convention.page.query.FilterCondition;
import io.gitee.pkmer.ddd.shared.command.CommandWithMark;
import io.gitee.pkmer.ddd.shared.service.CmdService;
import lombok.Data;
import lombok.Value;
import org.hzz.promotions.types.constants.UserCouponFields;
import org.hzz.promotions.types.req.UserCouponPageReq;
import org.hzz.promotions.types.vo.UserCouponVo;

import java.util.List;

import static io.gitee.pkmer.convention.page.query.FilterCondition.Operation.EQ;

/**
 * @author <a href="mailto:1193094618@qq.com">pkmer</a>
 * <br>
 * <a href = "https://gitee.com/developeros/videos-online">Code Repository</a>
 * At 2024/9/4
 * 用户的优惠券分页查询命令
 * {@link org.hzz.application.handler.user.UserCouponPageCmdHandler}
 */
@Data
@Value(staticConstructor = "commandOf")
public class UserCouponPageCmd implements CommandWithMark {
    public static final String MARK = UserCouponPageCmd.class.getName();

    UserCouponPageReq page;
    Long userId;

    @Override
    public String mark() {
        return MARK;
    }

    public PageResponse<UserCouponVo> executeWithResult(CmdService cmdService) {
        handleFilter();
        return cmdService.handleCommandWithResult(this);
    }

    private void handleFilter(){
        List<FilterCondition> filters = FilterCondition.createCriteria()
                .and(UserCouponFields.STATUS, EQ, page.getStatus())
                .and(UserCouponFields.USER_ID,EQ,userId)
                .build();

        page.setFilters(filters);
    }
}
